#!/bin/bash

[ -z "$ECHO_SCRIPT" ] && ECHO_SCRIPT=/home/EchoIRLP/scripts
   source $ECHO_SCRIPT/echo_common

if [ "$1" != "hostfile" ] && [ "$3" != ".version" ] && [ "$3" != "refresh" ] ; then
	log "$@"
fi
# Fix TERM setting so imike and others don't fail. (KF7FLY)
if [ "$TERM" = "" -o "$TERM" = "unknown" -o "$TERM" = "dumb" ] ; then
        export TERM=vt100
fi

if [ "$1" = "hostfile" ]; then
   if [ -f "$ECHO_SCRIPT/echo_update_hosts" ]; then
      "$ECHO_SCRIPT/echo_update_hosts"
   fi
fi

if [ "$1" = "starting" ]; then
   "$ECHO_SCRIPT"/echo_syscheck
fi

if [ -f "$LOCAL"/echo_conference ]; then 
   # tbd is configured to run as a conference.  Disable all interaction
   # between tbd and IRLP and run them independently.
   echo "${0##*/}: Conference mode, RF link disabled"
   exit 0
fi

if [ "$1" = "connected" ]; then
   if [ "$2" = "echolink" ]; then
      "$ECHO_SCRIPT"/echo_inbound $3 $4 $5
   elif [ "$2" = "outbound" ] ; then
      "$ECHO_SCRIPT"/call_status $3 $4 $5
   fi
  
fi

if [ "$1" = "disconnected" ]; then
   if [ "$2" = "refused" -a -f "$LOCAL/echo_pending" ]; then
      touch "$LOCAL/echo_refused"
   elif [ ! -f "$LOCAL/echo_refused" ]; then
      "$ECHO_SCRIPT/echo_disconnect" $3 $4 $2
   fi
fi

if [ "$1" = "command" ]; then
  if [ "$3" = "dtmf" ]; then
   "$ECHO_SCRIPT"/dtmfregen $4 $2
  fi
fi
